//
//  GatheringListCell.m
//  HAODE
//
//  Created by panquanReabam.com on 15/12/10.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "GatheringListCell.h"

@interface GatheringListCell()


@property(nonatomic,strong)UILabel *lineLabel;

@property (strong, nonatomic)  UIImageView *image;
@property (strong, nonatomic)  UILabel *payType;
@property (strong, nonatomic)  UILabel *status;
@property (strong, nonatomic)  UILabel *createDate;
@property (strong, nonatomic)  UILabel *orderType;
@property (strong, nonatomic)  UILabel *payAmount;
@end
@implementation GatheringListCell

- (void)awakeFromNib {
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        [self createView];
        [self setViewAutoLayout];
    }
    
    return self;
    
}
-(void)createView
{
  
    self.backgroundColor=[UIColor whiteColor];
    self.payAmount=[[UILabel alloc] init];
    self.payAmount.font= [UIFont systemFontOfSize:16];
    self.payAmount.frame=CGRectMake(ScreenWidth-200, 15, 180, 16);
    self.payAmount.textColor=[UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0];
    [self addSubview:self.payAmount];
    
    self.image=[[UIImageView alloc] init];
    [self addSubview:self.image];
    self.status=[[UILabel alloc] init];
    self.status.frame=CGRectMake(ScreenWidth-200, 40, 180, 12);
    self.status.font= [UIFont systemFontOfSize:12];
    self.status.textColor=luseColor;
    [self addSubview:self.status];
    self.createDate=[[UILabel alloc] init];
    self.createDate.font= [UIFont systemFontOfSize:12];
    self.createDate.textColor=zhonghuiColor;
    [self addSubview:self.createDate];
    
    self.payType=[[UILabel alloc] init];
    self.payType.font= [UIFont systemFontOfSize:15];
    self.payType.textColor=[UIColor blackColor];
    [self addSubview:self.payType];

    self.createDate=[[UILabel alloc] init];
    self.createDate.font= [UIFont systemFontOfSize:12];
    self.createDate.textColor=zhonghuiColor;
    [self addSubview:self.createDate];
   
    self.orderType=[[UILabel alloc] init];
    self.orderType.font= [UIFont systemFontOfSize:8];
    self.orderType.textColor=[UIColor whiteColor];
    [self addSubview:self.orderType];
    
    self.lineLabel=[[UILabel alloc] init];
    [self.lineLabel setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0f]];
    self.lineLabel.textColor=[UIColor clearColor];
    [self addSubview:self.lineLabel];
    
    
}
-(void)setModel:(GatheringListModel *)model
{
    
   
   
    [self.image.layer setCornerRadius:6.0];
    [self.image.layer setBorderWidth:0.3];
    [self.image.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [self.image.layer setBorderColor:colorref2];//边框颜色
    if ([model.payType isEqualToString:@"wx_pay_scan"]) {
        self.payType.text=[NSString stringWithFormat:@"%@",  @"微信扫码支付"];
        [self.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"weixinkuang"]];
    }
    if ([model.payType isEqualToString:@"CashPay"]) {
        self.payType.text=[NSString stringWithFormat:@"%@",  @"现金支付"];
        [self.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"xianjin"]];
    }
    if ([model.payType isEqualToString:@"IboxPay"]) {
        self.payType.text=[NSString stringWithFormat:@"%@",  @"盒子支付"];
        [self.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"shuakas"]];
    }
    if ([model.payType isEqualToString:@"AliQrPay"]) {
        self.payType.text=[NSString stringWithFormat:@"%@",  @"支付宝支付"];
        [self.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"zhifubaos"]];
    }
   
    
    NSRange range={0,16};
    NSString* string =[[NSString stringWithFormat:@"%@",model.createDate ] substringWithRange:range];
    self.createDate.text =[NSString stringWithFormat:@"%@",string];
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",model.payAmount];
    
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    self.payAmount.textAlignment=NSTextAlignmentRight;
    self.payAmount.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];

    self.status.textAlignment=NSTextAlignmentRight;
    if ([model.status isEqualToString:@"Y"]) {
        self.status.text =[NSString stringWithFormat:@"%@",@"交易成功"];
        self.status.textColor=shenhuiColor;
        
        
        
    }else{
        self.status.text =[NSString stringWithFormat:@"%@",@"交易失败"];
        self.status.textColor=hongseColor;
    }
    
    
    
    self.lineLabel.text=[NSString stringWithFormat:@"%@",model.status];
    
    if ([model.orderType isEqualToString:@"order"]) {
        self.orderType.text =[NSString stringWithFormat:@"%@",@"订单"];
        self.orderType.textColor=[UIColor whiteColor];
        self.orderType.backgroundColor=luseColor;
        self.orderType.textAlignment=NSTextAlignmentCenter;
        
        
    }
    if ([model.orderType isEqualToString:@"service"]) {
        self.orderType.text =[NSString stringWithFormat:@"%@",@"服务"];
        self.orderType.textColor=[UIColor whiteColor];
        self.orderType.backgroundColor=[UIColor colorWithRed:209/255.0 green:170/255.0 blue:56/255.0 alpha:1.0];
        self.orderType.textAlignment=NSTextAlignmentCenter;
    }
    
    if ([model.orderType isEqualToString:@"other"]) {
        self.orderType.text =[NSString stringWithFormat:@"%@",@"自定义"];
        self.orderType.textColor=[UIColor whiteColor];
        self.orderType.backgroundColor=zhonghuiColor;
        self.orderType.textAlignment=NSTextAlignmentCenter;
        
    }
    

    
}
-(void)setViewAutoLayout
{
    [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@45);
        make.width.equalTo(@45);
        make.top.equalTo(self.mas_top).with.offset(15);
    }];
    
    [self.payType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.image.mas_right).with.offset(10);
        make.top.equalTo(self.mas_top).with.offset(15);
    }];
    
    
    [self.createDate mas_makeConstraints:^(MASConstraintMaker *make) {
        
         make.left.equalTo(self.image.mas_right).with.offset(10);
        make.top.equalTo(self.payType.mas_bottom).with.offset(5);
    }];
    
    [self.orderType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.image.mas_right).with.offset(10);

        make.height.equalTo(@12);
        make.width.equalTo(@25);
        make.top.equalTo(self.createDate.mas_bottom).with.offset(5);
        
    }];
//    [self.createDate mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(self.createName1.mas_right).with.offset(15);
//        
//        make.height.equalTo(@14);
//        
//        make.centerY.equalTo(self.createName.mas_centerY) ;
//        
//    }];
//    
//    [self.createDate1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.createDate.mas_right).with.offset(3);
//        make.height.equalTo(@14);
//        
//        make.centerY.equalTo(self.createDate.mas_centerY) ;
//        
//    }];
//    
//    
//    [self.itemTypes mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(self.mas_left).with.offset(15) ;
//        make.height.equalTo(@14);
//        make.top.equalTo(self.createDate1.mas_bottom).with.offset(5);
//    }];
//    
//    [self.itemTypes1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.itemTypes.mas_right).with.offset(3);
//        make.height.equalTo(@14);
//        
//        make.centerY.equalTo(self.itemTypes.mas_centerY) ;
//        
//    }];
//    
//    [self.totalMoney mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(self.itemTypes1.mas_right).with.offset(15);
//        make.height.equalTo(@14);
//        make.centerY.equalTo(self.itemTypes.mas_centerY) ;
//    }];
//    
//    [self.totalMoney1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.totalMoney.mas_right).with.offset(0);
//        make.height.equalTo(@14);
//        
//        make.centerY.equalTo(self.itemTypes.mas_centerY) ;
//        
//        
//    }];
//    
//    
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10) ;
        
        make.height.equalTo(@1);
        
        make.top.equalTo(@80).with.offset(0);
    }];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
